/**
 * Created by Administrator on 2017/9/21.
 */
angular.module('module.saleStatistics')
    .controller('BookController', BookController);
BookController.$inject = ['$localStorage', '$state', '$scope', 'shopBookList'];
function BookController($localStorage, $state, $scope, shopBookList) {
    var vm = this;
    vm.sureBtn = sureBtn; // 模态框
    vm.cancelBtn = cancelBtn; // 模态框
    vm.checkedData = checkedData;
    vm.img = img1;
    vm.checked = false;

    function sureBtn() {
        vm.messageVisible = false;
    }

    function cancelBtn() {
        vm.messageVisible = false;
    }

    // 获取当前日期及前七天的日期
    if (!$localStorage[environmental + "shopid"]) {
        $localStorage.$reset();
        $state.go('login');
    }

    if (shopBookList == 'undefined') {
        vm.bookNum = [];
    } else {
        vm.bookNum = shopBookList;
    }
    var myDate = new Date();
    var mystatime = new Date(myDate.getFullYear(), myDate.getMonth(), myDate.getDate() - 6, 0, 0, 0); // 默认七天前的时间
    vm.tur_statime = getstart(mystatime, 0);
    vm.tur_endtime = getstart(new Date(), 1); // 初始时间;
    var timelist = {
        statime: Date.parse(mystatime),
        endtime: Date.parse(new Date()),
    };

    $('#starttime').datetimepicker({
        format: "yyyy-MM-dd",
        autoclose: true,
        todayBtn: true,
        pickerPosition: "bottom-right",
        minView: 2,
        endDate: new Date(),
    }).on('changeDate', function (ev) {
        timelist.statime = jonsr(getstart(ev.date, 0));
        if (timelist.endtime == null || timelist.endtime == "") {
            $scope.$apply(function () {
                vm.tur_statime = getstart(ev.date, 0);
            })
        } else {
            if (timelist.statime > timelist.endtime) {
                vm.messageVisible = true;
                vm.message = "请输入正确的时间格式！";
                return;
            }
            $scope.$apply(function () {
                vm.tur_statime = getstart(ev.date, 0);
            })
        }
    });

    $('#endtime').datetimepicker({
        format: "yyyy-MM-dd",
        autoclose: true,
        todayBtn: true,
        pickerPosition: "bottom-right",
        minView: 2,
        endDate: new Date(),
    }).on('changeDate', function (ev) {
        timelist.endtime = jonsr(getstart(ev.date, 1));
        if (timelist.endtime == null || timelist.endtime == "") {
            $scope.$apply(function () {
                vm.tur_endtime = getstart(ev.date, 1);
            })
        } else {
            if (timelist.statime > timelist.endtime) {
                vm.messageVisible = true;
                vm.message = "请输入正确的时间格式！";
                return;
            }
            $scope.$apply(function () {
                vm.tur_endtime = getstart(ev.date, 1);
            })
        }
    });

    vm.tableNum = [{time: "09/11", num: 5}, {time: "09/11", num: 5},
        {time: "09/11", num: 5}, {time: "09/11", num: 5},
        {time: "09/11", num: 5}, {time: "09/11", num: 5},
        {time: "09/11", num: 5},
    ];

    vm.type = 3;
    function img1(type) {
        vm.type = type;
    }

    function checkedData() {
        vm.checked = true;
    }

    vm.option = option;
    var data = ['9/11', '9/12', '9/13', '9/14', '9/15', '9/16', '9/17', '9/14', '9/15', '9/16', '9/17'];
    var dataAxis = [25, 15, 30, 50, 70, 60, 50, 25, 55, 105, 110];
    var option = vm.option(data, dataAxis);
    var diagram = echarts.init(document.getElementById('tubiao'));
    diagram.setOption(option);

    function option(data, dataAxis) {
        return {
            tooltip: {
                trigger: 'axis'
            },
            grid: {
                x: 25,
                y: 15,
                x2: 25,
                y2: 15,
                borderWidth: 1

            },
            xAxis: {
                type: 'category',
                boundaryGap: false,
                data: data,
                axisLine: {
                    show: false
                },
                axisTick: {
                    show: false
                },
                splitLine: {
                    show: true,
                    lineStyle: {
                        color: '#5fe1d9'
                    }
                },
                axisLabel: {
                    show: false
                }
            },
            yAxis: {
                type: 'value',
                axisLine: {
                    show: false

                },
                axisTick: {
                    show: false
                }, splitLine: {
                    show: false
                },
                axisLabel: {
                    show: false
                }
            },
            series: [
                {
                    type: 'line',
                    symbol: 'none',
                    smooth: 'true',
                    itemStyle: {
                        normal: {
                            color: 'white',
                            lineStyle: {
                                normal: {
                                    width: 10,
                                    color: 'white'
                                }
                            },
                        }
                    },
                    data: dataAxis,
                },

            ]
        };
    }
}